﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Drawing.Design;
using ProgNetComponentsDx.Data.Design;
using ProgNetComponents.Interfaces;

namespace ProgNetComponentsDx.Data
{
    [TypeConverter(typeof(RecordSelectStructTypeConverter))]
    public class RecordSelectStruct : INamedObject
    {
        private string _DataSetTableName;
        private string _DataBaseTableName;
        private string _SelectString;

        public string DataSetTableName
        {
            get
            {
                if (_DataSetTableName.IsNull())
                    return _DataBaseTableName;
                return _DataSetTableName;
            }
            set { _DataSetTableName = value; }
        }
        public string DataBaseTableName
        {
            get
            {
                if (_DataBaseTableName.IsNull())
                    return _DataSetTableName;
                return _DataBaseTableName;
            }
            set { _DataBaseTableName = value; }
        }
        
        [Editor("System.ComponentModel.Design.MultilineStringEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
        public string SelectString
        {
            get
            {
                if (_SelectString.IsNull() && DataBaseTableName.IsNotNull())
                    return "SELECT * FROM " + DataBaseTableName;
                return _SelectString;
            }
            set
            {
                _SelectString = value;
            }
        }

        #region CTOR
        public RecordSelectStruct() { }

        public RecordSelectStruct(string selectString, string dataSetTableName, string dataBaseTableName)
        {
            SelectString = selectString;
            DataSetTableName = dataSetTableName;
            DataBaseTableName = dataBaseTableName;
        }
        public RecordSelectStruct(string selectString, string dataSetTableName)
            : this(selectString, dataSetTableName, null)
        {

        }
        public RecordSelectStruct(string dataSetTableName)
            : this(null, dataSetTableName, null)
        {

        }
        #endregion

        public override string ToString()
        {
            return "SELECT ... " + DataBaseTableName;
        }

        #region INamedObject Members
        [Browsable(false)]
        public string Name
        {
            get
            {
                return DataSetTableName;
            }
            set
            {
                
            }
        }

        #endregion
    }

    public class RecordSelectStructCollection : ProgNetComponents.Collections.BaseNamedCollection<RecordSelectStruct>
    {

    }

}
